import axios from "axios"

const axiosInstance = axios.create({
  baseURL: "",
  timeout: 10000,
  responseType: "json",
  headers: {
    "Content-Type": "application/json;charset=utf-8"
  }
})

axiosInstance.interceptors.request.use(
  config => {
    const token = window.localStorage.getItem("token")
    if (token) {
      config.headers.token = token
    }

    return config
  },
  error => Promise.reject(error)
)

axiosInstance.interceptors.response.use(
  result => {
    return result.data
  },
  error => {
    return Promise.reject(error)
  }
)

export default axiosInstance
